import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import FenLei from "../views/FenLei.vue";
import My from "../views/My.vue";
import PinDao from "../views/PinDao.vue";
import ShopCart from "../views/ShopCart.vue";
import MyTab from '../components/modules/MyTab.vue'
import login from "../components/modules/login.vue";
import register from "../components/modules/register.vue";
import MyCenter from "../components/modules/MyCenter.vue"
import FLlist from "../components/common/fenleiList.vue"
import logOut from "../components/modules/logOut.vue"
import goodsDetails from "../components/common/goodsDetails.vue"
import fenleiDet from "../components/common/fenleiDet.vue"
import goodsSort from "../components/common/goodsSort.vue"
import dingdan from "../components/common/dingdan.vue"
import ddContent from "../components/common/dingdanContent.vue"

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home
  },
  {
    path: "/fenlei",
    name: "FenLei",
    component: FenLei,
    redirect: '/fenlei/fenleiList/1',
    meta: { title: '分类' },
    children: [
      {
        path: "/fenlei/fenleiList/:id",
        name: "fenleiList",
        component: FLlist,
        meta: { title: '分类' }
      },
    ]
  },
  {
    path: "/fenleiDet/:index",
    name: "fenleiDet",
    component: fenleiDet,
    meta: { title: '分类' },
    redirect: '/fenleiDet/:index/goodsSort',
    children: [
      {
        path: "/fenleiDet/:index/goodsSort",
        name: "goodsSort",
        component: goodsSort,
        meta: { title: '分类' }
      }
    ]
  },
  {
    path: "/my",
    name: "My",
    component: My,
    redirect:"/my/MyCenter",
    children: [
      {
        path: "/my/MyTab",
        name: "MyTab",
        component: MyTab,
        children: [
          {
            path: "/my/MyTab/login",
            name: "login",
            component: login,
            meta: { title: '登录', isShow: true }
          },
          {
            path: "/my/MyTab/register",
            name: "register",
            component: register,
            meta: { title: '注册', isShow: true }
          }
        ]
      },
      {
        path: "/my/MyCenter",
        name: "MyCenter",
        component: MyCenter,
        meta: { title: '个人中心' },
      },
      {
        path: "/my/dingdan/:index",
        name: "dingdan",
        component: dingdan,
        meta: { title: '全部订单' },
        redirect:"/my/dingdan/:index/ddContent",
        children: [
          {
            path: "/my/dingdan/:index/ddContent",
            name: "ddContent",
            component: ddContent,
            meta: { title: '全部订单' },
          }
        ]
      },
      {
        path: "/my/logOut",
        name: "logOut",
        component: logOut,
        meta: { title: '修改个人信息' }
      }
    ],
  },
  {
    path: "/pindao",
    name: "PinDao",
    component: PinDao,
    meta: { title: '频道' }
  },
  {
    path: "/shopcart",
    name: "ShopCart",
    component: ShopCart,
    meta: { title: '购物车', isShow: true }
  },
  {
    path: "/goodsDetails/:index",
    name: "goodsDetails",
    component: goodsDetails,
    meta: { title: '商品详细', isShow: true }
  }
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
  linkActiveClass: 'activeBottom'
});
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
export default router;
